/**
 *轻云蒜瓣商城账户面板
 */
Ext.define("PRO.shop.view.useraccount.account",{
    extend: 'Ext.panel.Panel',
    layout:'fit',
    alias: 'widget.shop.account',
    cls:'accountCon',
    border:false,
    autoScroll:true,
    initComponent: function(){
        var me = this;
        //创建各项版块
        me.defaults = {columnWidth:1,border:0}
        var data = me.getData();
        me.getData = data;
        var accountId= JE.isNotEmpty(me.getData)?me.getData.accountId:'';
        me.items ={
            xtype:'panel',
            border:false,
            bodyStyle:'background:rgb(236, 240, 245)',
            autoScroll:true,
            defaults:{
                border:0
            },
            items:[
                {
                    xtype:'panel',
                    layout:'border',
                    itemId:'panel',
                    height:150,
                    style:'background:#fff;border-radius:4px;',
                    margin:'20px 0 20px 0',
                    items:[
                        {

                            region: 'west',
                            itemId:'west',
                            xtype: 'box',
                            data:data,
                            padding:'20px 20px 20px 40px',
                            width:700,
                            tpl:[
                                '<p class="accout-table-money">可用余额</p>',
                                '<p class="accout-table-money account-now-money">{currentAccountBalance}<span>元</span></p>',
                                '<p class="accout-table-money">历史充值总额：<span>{totalRechargeAmount}元</span> <i>|</i>历史消费总额：<span>{totalConsumeAmount}元</span></p>'
                            ]
                        },
                        {
                            region:'center',
                            xtype:'panel',
                            width:500,
                            border:false,
                            height:60,
                            cls:'account-center',
                            margin:'45 0',
                            items:[
                                {
                                    text:'微信充值',
                                    xtype:'button',
                                    border:0,
                                    icon:JE.buildCdnUrl('/pro/shop/resourse/weixin.png'),
                                    iconCls:'weixinStyle',
                                    cls:'btn JEPLUS_B_L10',
                                    height:60,
                                    width:190,
                                    margin:'0 30px 0 50px',
                                    style:'padding: 4px 20px !important;background:#51C332;line-height:50px;',
                                    handler:function(btn){
                                        me.goRecharge(btn,'wechatPay')
                                    }
                                },
                                {
                                    xtype:'button',
                                    text:'支付宝充值',
                                    border:0,
                                    height:60,
                                    width:190,
                                    iconCls:'weixinStyle',
                                    icon:JE.buildCdnUrl('/pro/shop/resourse/zhifubao.png'),
                                    cls:'btn JEPLUS_B_L10',
                                    style:'padding: 4px 20px !important;background:#03AAEE;line-height:50px;',
                                    handler:function(btn){
                                        me.goRecharge(btn,'aliPay')
                                    }
                                }
                            ]

                        }
                    ]
                },//商城/我的账户
                {
                    xtype:'panel',
                    columnWidth:.2,
                    itemId:'btnPanel',
                    cls:'buttonsPanel',
                    style:'position:absolute;right:40px;width:180px;;z-index:10;top:215px;background:rgb(246,249,252)',
                    buttons:[
                        {
                            xtype:'button',
                            cls:'buttonActive',
                            itemId:'recordRechargeBtn',
                            style:'border-radius:0;',
                            text:'充值记录',
                            border:false,
                            handler:function(btn){
                                btn.addCls('buttonActive');
                                btn.nextNode().removeCls('buttonActive');
                                btn.up('[itemId=btnPanel]').nextNode().getLayout().setActiveItem('recordRecharge')
                            }
                        },
                        {
                            xtype:'button',
                            itemId:'recordSaleBtn',
                            margin:'0 0 0 -10px',
                            style:'border-radius:0;',
                            text:'消费记录',
                            border:false,
                            handler:function(btn){
                                btn.addCls('buttonActive');
                                btn.previousNode().removeCls('buttonActive');
                                btn.up('[itemId=btnPanel]').nextNode().getLayout().setActiveItem('recordSale')
                            }
                        }
                    ]
                },
                {
                    xtype:'panel',
                    layout:'card',
                    itemId:'tablePanel',
                    autoScroll:true,
                    style:'z-index:1',
                    height:800,
                    items:[
                        {
                            xtype:'jemainview',
                            padding:'20',
                            itemId:'recordRecharge',
                            whereSql:" and JE_PAY_ACCOUNT_ID='"+accountId+"'",
                            funcData:JE.getFuncData('JE_ACCOUNT_DETAILS')//充值记录
                        },
                        {
                            xtype:'jemainview',
                            itemId:'recordSale',
                            padding:'20',
                            whereSql:" and JE_SAAS_YH_ID='"+JE.USER.zhId+"'", //JE_PAY_ACCOUNT
                            funcData:JE.getFuncData('JE_PURCHASE_RECORDS')//消费记录
                        }
                    ]
                }
            ]
        }
        me.callParent(arguments);
    },
    goRecharge:function(btn,selectType){
        var me = this;
        var win = JE.win({
            title:'账户充值',
            width:800,//JE.getBodyWidth()-750,
            height:600,//JE.getBodyHeight()-235,
            border:0,
            default:{border:0},
            draggable : false,
            autoShow:true,
            items:[{
                xtype:'shop.accountpay',
                selectType:selectType,
                accountPanel:me
            }]
        });
        win.on('close',function(){
            var data = JE.ajax({
                url:'/je/shoppingmall/bill/getAccountDetail',
                params:{}
            })
            if(data.success){
                var data = {
                    currentAccountBalance:data.obj.currentAccountBalance=='0'?'0.00':data.obj.currentAccountBalance,//
                    totalConsumeAmount:data.obj.totalConsumeAmount   ,
                    totalRechargeAmount:data.obj.totalRechargeAmount,
                    accountId:data.obj.accountId
                }
                var panel = btn.up('[itemId=panel]');
                var west = panel.getCmp('west');
                panel.nextNode().nextNode().down('panel[xtype=jegridview]').store.load()
                west.update(data);
            }

        })
    },
    getData:function(){
        var me = this;
        var data = JE.ajax({
            url:'/je/shoppingmall/bill/getAccountDetail',
            params:{}
        })
        if(data.success){
            return data = {
                currentAccountBalance:data.obj.currentAccountBalance=='0'?'0.00':data.obj.currentAccountBalance,//
                totalConsumeAmount:data.obj.totalConsumeAmount   ,
                totalRechargeAmount:data.obj.totalRechargeAmount,
                accountId:data.obj.accountId
            }
        }
    }
});
